package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.pon.GetFinalResult;
import com.chinanet.utils.pon.HW_Socket_AttrsIn;
import com.chinanet.utils.pon.H_SocketClient;
import com.chinanet.utils.pon.OperationType;

import java.util.HashMap;
import java.util.Map;
/**
 * Query_PON_OLT_under_the_number_of_alarmImp
 * 华为PON网管-查询OLT PON下的告警数量
 * 华为PON网管-查询OLT PON下的告警数量
 * @author xuzhi
 *
 */
public class HW_Query_PON_OLT_under_the_number_of_alarmImp implements WorkInterFace {

	public String getName() {
		return "华为PON网管查询OLT PON下的告警数量";
	}

	public String getDesciption() {
		return "测试方法";
	}

	public int getVersion() {
		return 0;
	}

	public Attr[] getInAttrs() {
		Attr[] in = new Attr[3];
//		in[0] = new Attr("Port", "端口号", AttrType.TYPE_String, true);
		in[0] = new Attr("OLTID", "OLT的ID", AttrType.TYPE_String, true);
		in[1] = new Attr("BEGINTIME", "开始时间,格式：yyyy-MM-dd HH-mm-ss", AttrType.TYPE_Date, true);
		in[2] = new Attr("PONID", "PON的ID，如：查询OLT设备上0框4槽1端口的光模块信息，PONID为NA-0-4-1", AttrType.TYPE_String, true);
//		in[3] = new Attr("ENDTIME", "结束时间，格式：yyyy-MM-dd HH-mm-ss", AttrType.TYPE_Date, false);
		return in;
	}

	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[8];
		out[0] = new Attr("flag", "操作是否成功，1：成功，0：失败", AttrType.TYPE_Int, true);
		out[1] = new Attr("Alarmfalg", "查询改pon下是否存在pon LOS告警，1：存在；0：不存在", AttrType.TYPE_Int, true);
		out[2] = new Attr("DGinum", "PON口掉电的告警数量", AttrType.TYPE_Int, true);
		out[3] = new Attr("DGiTimeflag", "PON口掉电时的时间正确度，1：正确；0：不正确", AttrType.TYPE_Int, true);
		out[4] = new Attr("LOSinum", "断纤告警数量", AttrType.TYPE_Int, true);
		out[5] = new Attr("LOSiTimeflag", "断纤时的时间正确度，1：正确；0：不正确", AttrType.TYPE_Int, true);
		out[6] = new Attr("ONTlosflag","多个ONT掉电",AttrType.TYPE_Int,true);
		out[7] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
		return out;
	}

	public Map<String, Object> init(Map<String, Object> data) {
		Map<String, Object> inmap = new HashMap<String, Object>();
		Map<String, Object> intomap = new HashMap<String, Object>();
		Map<String, Object> outmap = new HashMap<String, Object>();
		GetFinalResult result = new GetFinalResult();
		String ip = "134.103.69.185";
		int port = 13028;
		H_SocketClient hclient = new H_SocketClient(ip, port);
		HW_Socket_AttrsIn attrsin = new HW_Socket_AttrsIn();
		attrsin.setUsername("nxzcxc");
		attrsin.setPassword("asdf1234");
		attrsin.setOLTID((String) data.get("OLTID"));
		attrsin.setPONID((String) data.get("PONID"));

		//Date begintime=(Date) data.get("BEGINTIME");
		//Date endtime=(Date) data.get("ENDTIME");
//		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
//		String BEGINTIME=sdf.format(begintime);
//		String ENDTIME=sdf.format(endtime);

		String BEGINTIME=(String) data.get("BEGINTIME");
//		String ENDTIME=(String) data.get("ENDTIME");
		attrsin.setBEGINTIME(BEGINTIME);
//		attrsin.setENDTIME(ENDTIME);


		inmap = hclient.init(attrsin,
				OperationType.TYPE_Query_PON_OLT_under_the_number_of_alarms);

		try {
			intomap = result.getPatterns_ALARM((String) inmap.get("ownlog"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		boolean flag = (Boolean) inmap.get("flag");
		if (flag) {
			outmap.put("flag", 1);
			outmap.put("log", inmap.get("log"));
		} else {
			outmap.put("flag", 0);
			outmap.put("log", inmap.get("log"));
		}
			outmap.putAll(intomap);

        /**
         * test
         */
//		Map<String, Object> outmap = new HashMap<String, Object>();
//		for (Map.Entry<String, Object> entry : data.entrySet()){
//			System.out.println(entry.getKey()+":"+entry.getValue());
//		}
//
//		outmap.put("flag",1);
//		outmap.put("block_records",100);
//		outmap.put("log","执行了Query_PON_port_luminous_powerImp");


//        Test test=new Test();
//        String txt=test.GetForkText("d:\\test1\\file1.txt");
//        try {
//            intomap = result.getPatterns_ALARM(txt);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//            outmap.put("flag", 1);
//            outmap.put("log", txt);
//        outmap.putAll(intomap);
		return outmap;
	}

}
